﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using SWEN_HMS.Classes;

namespace SWEN_HMS.UserModule
{
    public partial class Change_Password : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["staffid"] == null)
            {
                Response.Redirect("~/UserModule/Login.aspx");
            }
            else if ((Convert.ToString(Session["accessLvl"])) == "No Access")
            {
                Response.Redirect("~/UserModule/Login.aspx");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            staff s = new staff();

            EncodingAndDecodingcs en = new EncodingAndDecodingcs();
            if (en.Encode(tbxPw.Text) == (string)Session["PW"])
            {
                int row = userDB.updatePW(s, en.Encode(tbxRPW.Text), (string)Session["PW"]);
                if (row > 0)
                {
                    System.Windows.Forms.MessageBox.Show("Password Changed!");
                    Session["PW"] = en.Encode(tbxRPW.Text);
                    Response.Redirect("~/UserModule/AccountManagement.aspx");
                }
                else
                {
                    lblmessage.Text = "Password update Unsuccessful!";
                }
            }
            else
            {
                lblmessage.Text = "Incorrect Password!";
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/UserModule/AccountManagement.aspx");
        }

       
    }
}